/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaCompra.java
 *
 * Created on 22-dic-2011, 11:13:56
 */
package invsys.Vistas;

import invsys.Controladores.ControlCompra;
import invsys.Controladores.ControlDetalleCompra;
import invsys.Controladores.ControlProducto;
import invsys.Controladores.ControlProveedor;
import invsys.Controladores.ControlUsuario;
import invsys.Controladores.ControlVariable;
import invsys.Modelo.Compra;
import invsys.Modelo.DetalleCompra;
import invsys.Modelo.Producto;
import invsys.Modelo.Proveedor;
import invsys.Modelo.Usuario;
import invsys.Modelo.Variable;
import invsys.Utilidades.ManejadorBaseDatos;
import invsys.Utilidades.ValidarorVistas;
import invsys.Principal;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author luigie
 */
public class VistaCompra extends javax.swing.JDialog {
    ValidarorVistas vistas = new ValidarorVistas();
    DefaultTableModel dtm = new DefaultTableModel();
    DefaultTableModel dtm2 = new DefaultTableModel();
    DefaultTableModel dtm3 = new DefaultTableModel();
    SimpleDateFormat cfecha = new SimpleDateFormat("dd/MM/yyyy");
    String i;
    Date date;
    /** Creates new form VistaCompra */
    public VistaCompra(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(this);
        date= new Date();
        fechaCompra.setDate(date);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buscarProveedor = new javax.swing.JDialog();
        jPanel6 = new invsys.Imagenes.Fondo.panel("buscarclientes.png");
        ComboProveedor = new javax.swing.JComboBox();
        BuscarProve = new javax.swing.JTextField();
        jScrollPane5 = new javax.swing.JScrollPane();
        jXTable4 = new org.jdesktop.swingx.JXTable(dtm);
        jButton9 = new javax.swing.JButton();
        NuevoProducto = new javax.swing.JDialog();
        jPanel7 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        txtNuevNit = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtNuevNombre = new javax.swing.JTextField();
        jPanel9 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        txtNuevCodigo = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        txtNuevTipo = new javax.swing.JTextField();
        txtNuevNombrepro = new javax.swing.JTextField();
        txtNuevprecio = new javax.swing.JTextField();
        jScrollPane6 = new javax.swing.JScrollPane();
        txtNuevDescripcion = new javax.swing.JTextArea();
        txtNuevCantidad = new javax.swing.JTextField();
        txtNuevPrecioCompra = new javax.swing.JTextField();
        txtNuevStockMin = new javax.swing.JTextField();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        mensaje2 = new javax.swing.JLabel();
        jButton13 = new javax.swing.JButton();
        Cantidad = new javax.swing.JDialog();
        jPanel11 = new javax.swing.JPanel();
        txtCant = new javax.swing.JTextField();
        txtPrecioC = new javax.swing.JTextField();
        txtPrecioV = new javax.swing.JTextField();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jPanel1 = new invsys.Imagenes.Fondo.panel("inventario4.png");
        jPanel2 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jLabel1 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtNit = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        jPanel3 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable(dtm2);
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel10 = new invsys.Imagenes.Fondo.panel("transparente.png");
        txtBuscarProducto = new javax.swing.JTextField();
        comboProducto = new javax.swing.JComboBox();
        jPanel4 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jLabel6 = new javax.swing.JLabel();
        fechaCompra = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        numeroCompra = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jXTable3 = new org.jdesktop.swingx.JXTable(dtm3);
        jButton5 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        responsable = new javax.swing.JTextField();
        jPanel5 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jLabel10 = new javax.swing.JLabel();
        subtotal = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        iva = new javax.swing.JTextField();
        total = new javax.swing.JTextField();
        responsablenom = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jPanel12 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jScrollPane4 = new javax.swing.JScrollPane();
        observacion = new javax.swing.JTextArea();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        mensaje = new javax.swing.JLabel();

        buscarProveedor.setMinimumSize(new java.awt.Dimension(400, 330));
        buscarProveedor.setModal(true);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Buscar Proveedor", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N

        ComboProveedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nit:", "Nombre:" }));

        BuscarProve.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                BuscarProveKeyReleased(evt);
            }
        });

        dtm.addColumn("Nit");
        dtm.addColumn("Nombre");
        dtm.addColumn("Dirección");
        dtm.addColumn("Telefono");
        jXTable4.setEditable(false);
        jXTable4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXTable4MouseClicked(evt);
            }
        });
        jXTable4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jXTable4KeyPressed(evt);
            }
        });
        jScrollPane5.setViewportView(jXTable4);

        jButton9.setText("Salir");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(ComboProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BuscarProve, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(130, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(282, Short.MAX_VALUE)
                .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BuscarProve, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton9))
        );

        javax.swing.GroupLayout buscarProveedorLayout = new javax.swing.GroupLayout(buscarProveedor.getContentPane());
        buscarProveedor.getContentPane().setLayout(buscarProveedorLayout);
        buscarProveedorLayout.setHorizontalGroup(
            buscarProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buscarProveedorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        buscarProveedorLayout.setVerticalGroup(
            buscarProveedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buscarProveedorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        NuevoProducto.setMinimumSize(new java.awt.Dimension(610, 410));
        NuevoProducto.setModal(true);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Productos", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Proveedor"));

        jLabel13.setText("NIt:");

        txtNuevNit.setEditable(false);

        jLabel14.setText("Nombre:");

        txtNuevNombre.setEditable(false);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtNuevNit, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNuevNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                .addGap(36, 36, 36))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtNuevNit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNuevNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Producto"));

        jLabel15.setText("Codigo:");

        txtNuevCodigo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtNuevCodigoFocusGained(evt);
            }
        });

        jLabel16.setText("Tipo:");

        jLabel17.setText("Nombre:");

        jLabel18.setText("Descripcion:");

        jLabel19.setText("P. Venta:");

        jLabel20.setText("Cantidad:");

        jLabel21.setText("P. Compra:");

        jLabel22.setText("StockMin:");

        txtNuevprecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNuevprecioKeyReleased(evt);
            }
        });

        txtNuevDescripcion.setColumns(20);
        txtNuevDescripcion.setRows(5);
        jScrollPane6.setViewportView(txtNuevDescripcion);

        txtNuevCantidad.setText("0");
        txtNuevCantidad.setToolTipText("");
        txtNuevCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNuevCantidadKeyReleased(evt);
            }
        });

        txtNuevPrecioCompra.setText("0");
        txtNuevPrecioCompra.setToolTipText("");
        txtNuevPrecioCompra.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNuevPrecioCompraKeyReleased(evt);
            }
        });

        txtNuevStockMin.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNuevStockMinKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNuevCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                            .addComponent(txtNuevNombrepro)))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel20)
                            .addComponent(jLabel22))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNuevStockMin)
                            .addComponent(txtNuevCantidad, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))))
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel21)
                            .addComponent(jLabel16)
                            .addComponent(jLabel19)))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel18)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtNuevPrecioCompra, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                        .addComponent(txtNuevprecio)
                        .addComponent(txtNuevTipo))
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(11, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtNuevTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(txtNuevCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel19)
                    .addComponent(txtNuevNombrepro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNuevprecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel20)
                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtNuevCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel21)
                        .addComponent(txtNuevPrecioCompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel22)
                        .addComponent(txtNuevStockMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel18))
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jButton10.setText("Salir");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.setText("Limpiar");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.setText("Registrar");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        mensaje2.setFont(new java.awt.Font("Tahoma", 0, 12));
        mensaje2.setForeground(new java.awt.Color(255, 0, 0));

        jButton13.setText("Editar");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(mensaje2, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton10))
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
                    .addComponent(mensaje2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout NuevoProductoLayout = new javax.swing.GroupLayout(NuevoProducto.getContentPane());
        NuevoProducto.getContentPane().setLayout(NuevoProductoLayout);
        NuevoProductoLayout.setHorizontalGroup(
            NuevoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NuevoProductoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        NuevoProductoLayout.setVerticalGroup(
            NuevoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NuevoProductoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Cantidad.setMinimumSize(new java.awt.Dimension(545, 160));
        Cantidad.setModal(true);
        Cantidad.setUndecorated(true);
        Cantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                CantidadKeyPressed(evt);
            }
        });

        jPanel11.setBackground(new java.awt.Color(255, 255, 255));
        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Compra", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N

        txtCant.setFont(new java.awt.Font("SansSerif", 1, 36));
        txtCant.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCant.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cantidad", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N
        txtCant.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCantActionPerformed(evt);
            }
        });
        txtCant.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtCantKeyReleased(evt);
            }
        });

        txtPrecioC.setFont(new java.awt.Font("SansSerif", 1, 36));
        txtPrecioC.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtPrecioC.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Precio Compra", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N
        txtPrecioC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPrecioCActionPerformed(evt);
            }
        });
        txtPrecioC.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPrecioCKeyReleased(evt);
            }
        });

        txtPrecioV.setFont(new java.awt.Font("SansSerif", 1, 36));
        txtPrecioV.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtPrecioV.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Precio Venta", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N
        txtPrecioV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPrecioVActionPerformed(evt);
            }
        });
        txtPrecioV.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPrecioVKeyReleased(evt);
            }
        });

        jButton14.setText("Aceptar");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton15.setText("Cancelar");
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtCant, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtPrecioV, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtPrecioC, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addGap(175, 175, 175)
                        .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCant, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPrecioV, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPrecioC, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout CantidadLayout = new javax.swing.GroupLayout(Cantidad.getContentPane());
        Cantidad.getContentPane().setLayout(CantidadLayout);
        CantidadLayout.setHorizontalGroup(
            CantidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        CantidadLayout.setVerticalGroup(
            CantidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Compra");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Realizar Compra", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Proveedor"));

        jLabel1.setText("Proveedor:");

        txtNombre.setEditable(false);

        jButton1.setText("Buscar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Nit:");

        txtNit.setEditable(false);

        jLabel3.setText("Telefono:");

        txtTelefono.setEditable(false);

        jLabel4.setText("Dirección:");

        txtDireccion.setEditable(false);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Productos del Proveedor"));

        dtm2.addColumn("Codigo");
        dtm2.addColumn("Tipo");
        dtm2.addColumn("Nombre");
        dtm2.addColumn("Descripción");
        dtm2.addColumn("PrecioVenta");
        dtm2.addColumn("PrecioCompra");
        dtm2.addColumn("Cantidad");
        dtm2.addColumn("StockMin");
        jXTable1.setEditable(false);
        jXTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXTable1MouseClicked(evt);
            }
        });
        jXTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jXTable1KeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jXTable1);

        jButton2.setText("Agregar");
        jButton2.setEnabled(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Editar");
        jButton3.setEnabled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Nuevo");
        jButton4.setEnabled(false);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar"));

        txtBuscarProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtBuscarProductoKeyReleased(evt);
            }
        });

        comboProducto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nombre", "Codigo" }));

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(comboProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(txtBuscarProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(comboProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(txtBuscarProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 611, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(390, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addGap(282, 282, 282))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNit)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(29, 29, 29)
                                .addComponent(jButton1))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(37, 37, 37)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(40, 40, 40)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de la Compra"));

        jLabel6.setText("Fecha de compra:");

        jLabel7.setText("Numero de Compra:");

        numeroCompra.setForeground(new java.awt.Color(0, 51, 204));

        dtm3.addColumn("Codigo");
        dtm3.addColumn("Nombre");
        dtm3.addColumn("Descripcion");
        dtm3.addColumn("PrecioVenta");
        dtm3.addColumn("PrecioCompra");
        dtm3.addColumn("Cantdad");
        dtm3.addColumn("Subtotal");
        jXTable3.setEditable(false);
        jXTable3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXTable3MouseClicked(evt);
            }
        });
        jXTable3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jXTable3KeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(jXTable3);

        jButton5.setText("Quitar Producto");
        jButton5.setEnabled(false);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel5.setText("Responsable:");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Valor a Pagar"));

        jLabel10.setText("Subtotal:");

        subtotal.setEditable(false);

        jLabel11.setText("Iva:");

        jLabel12.setText("Total:");

        iva.setEditable(false);

        total.setEditable(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(total)
                    .addComponent(iva)
                    .addComponent(subtotal, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(iva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12)
                    .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jLabel8.setText("Identificacion:");

        jLabel23.setText("Nombre:");

        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder("obserbaciones"));

        observacion.setColumns(20);
        observacion.setRows(5);
        jScrollPane4.setViewportView(observacion);

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel12Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fechaCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(43, 43, 43)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(numeroCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 635, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel23)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(responsable, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(responsablenom, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 432, Short.MAX_VALUE)
                                .addComponent(jButton5)
                                .addGap(29, 29, 29)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(fechaCompra, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING))
                    .addComponent(numeroCompra, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton5)
                            .addComponent(jLabel5))
                        .addGap(11, 11, 11)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(responsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(responsablenom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel23)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(19, 19, 19))
        );

        jButton6.setText("Realizar Compra");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Cancelar");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Salir");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        mensaje.setFont(new java.awt.Font("Tahoma", 0, 12));
        mensaje.setForeground(new java.awt.Color(204, 0, 0));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(mensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 319, Short.MAX_VALUE)
                .addComponent(jButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton8)
                .addGap(21, 21, 21))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(mensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton6)
                        .addComponent(jButton7)
                        .addComponent(jButton8)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      if(jXTable3.getRowCount() == 0){
          ListarProveedor();
          BuscarProve.setText("");
          buscarProveedor.setLocationRelativeTo(this);
          buscarProveedor.setVisible(true);
      }else{
        if(JOptionPane.showConfirmDialog(this, "Desea Elegir otro Proveedo? \nSi elige otro proveedor la compra se borrara", "Atencion!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null) == 0){
            Limpiar(); 
            ListarProveedor();
            BuscarProve.setText("");
            buscarProveedor.setLocationRelativeTo(this);
            buscarProveedor.setVisible(true);
        }
              
      }
      
    }//GEN-LAST:event_jButton1ActionPerformed

    private void BuscarProveKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BuscarProveKeyReleased
      if(ComboProveedor.getSelectedItem().toString().equals("Nit:")){
           listaProveedorNit(BuscarProve.getText());
      }else{
          listaProveedornombre(BuscarProve.getText());
      }
       
    }//GEN-LAST:event_BuscarProveKeyReleased

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
       this.setVisible(false);
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jXTable4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable4MouseClicked
      
    }//GEN-LAST:event_jXTable4MouseClicked

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
       buscarProveedor.setVisible(false);
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
       if(vistas.CamposVacios(txtNit)){
           LimpiarNuevoProducto();
           txtNuevNit.setText(txtNit.getText());
           txtNuevNombre.setText(txtNombre.getText());
           jButton12.setEnabled(true);
            jButton13.setEnabled(false);
            //txtNuevPrecioCompra.setEnabled(false);
           NuevoProducto.setLocationRelativeTo(this);
           NuevoProducto.setVisible(true);
       }else{
           mensaje.setText("Seleccione Primero el Proveedor");
           vistas.RetornaColor(txtNit);
       }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
       NuevoProducto.setVisible(false);
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
      if(vistas.CamposVacios(txtNuevTipo,txtNuevNombrepro,txtNuevprecio,txtNuevCantidad,txtNuevStockMin) && !txtNuevDescripcion.getText().equals("")){
           try {
            Producto p = ControlProducto.BuscarProducto(txtNuevCodigo.getText());
            if(p == null){
                p=new Producto();
                p.setCodigo(txtNuevCodigo.getText());
                p.setTipo(txtNuevTipo.getText());
                p.setNombre(txtNuevNombrepro.getText());
                p.setPrecio(Double.parseDouble(txtNuevprecio.getText()));
                p.setCantidad(Double.parseDouble(txtNuevCantidad.getText()));
                p.setPreciocompra(Double.parseDouble(txtNuevPrecioCompra.getText()));
                p.setStockMin(Double.parseDouble(txtNuevStockMin.getText()));
                p.setDescripcion(txtNuevDescripcion.getText());
                p.setProveedor(ControlProveedor.BuscarProveedor(txtNuevNit.getText()));
                ControlProducto.RegistrarProducto(p);
                vistas.VaciarCampos(txtNuevTipo,txtNuevNombrepro,txtNuevprecio,txtNuevPrecioCompra,txtNuevStockMin);
                txtNuevCantidad.setText("0");
                txtNuevPrecioCompra.setText("0");
                txtNuevDescripcion.setText("");
                //NuevoProducto.setVisible(false);
                listaProductos();
            }
        }   catch (IOException ex) {
                Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
      }else{
          mensaje2.setText("No Pueden quedar Campos Vacios");
      }
       
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        vistas.VaciarCampos(txtNuevCodigo,txtNuevTipo,txtNuevNombrepro,txtNuevprecio,txtNuevPrecioCompra,txtNuevStockMin);
        txtNuevCantidad.setText("0");
        vistas.RetornaColor(txtNuevprecio,txtNuevCantidad,txtNuevPrecioCompra,txtNuevStockMin,txtNuevTipo,txtNuevNombrepro);
        txtNuevDescripcion.setText("");
    }//GEN-LAST:event_jButton11ActionPerformed

    private void txtNuevCantidadKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNuevCantidadKeyReleased
        vistas.validarnumero(txtNuevCantidad, mensaje2);
    }//GEN-LAST:event_txtNuevCantidadKeyReleased

    private void txtNuevprecioKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNuevprecioKeyReleased
       vistas.validarnumero(txtNuevprecio, mensaje2);
    }//GEN-LAST:event_txtNuevprecioKeyReleased

    private void txtNuevPrecioCompraKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNuevPrecioCompraKeyReleased
       vistas.validarnumero(txtNuevPrecioCompra, mensaje2);
    }//GEN-LAST:event_txtNuevPrecioCompraKeyReleased

    private void txtNuevStockMinKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNuevStockMinKeyReleased
       vistas.validarnumero(txtNuevStockMin, mensaje2);
    }//GEN-LAST:event_txtNuevStockMinKeyReleased

    private void txtBuscarProductoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBuscarProductoKeyReleased
      
     listaBuscarProducto();   
        
    }//GEN-LAST:event_txtBuscarProductoKeyReleased

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        int x = jXTable1.getSelectedRow();
        if(x <0){
            mensaje.setText("Seleccione Primero el Contacto");
        }else{
                i = dtm2.getValueAt(x, 0).toString();
                if (vistas.CamposVacios(txtNit)) { 
                try {
                    Producto p;
                    int num;
                    LimpiarNuevoProducto();
                    p = ControlProducto.BuscarProducto(i);
                    txtNuevCodigo.setText(p.getCodigo());
                    txtNuevTipo.setText(p.getTipo());
                    txtNuevNombrepro.setText(p.getNombre());
                    txtNuevprecio.setText(p.getPrecio()+"");
                    num = (int) p.getCantidad();
                    txtNuevCantidad.setText(num+"");
                    num = (int) p.getPreciocompra();
                    txtNuevPrecioCompra.setText(num+"");
                    num = (int) p.getStockMin();
                    txtNuevStockMin.setText(num+"");
                    txtNuevDescripcion.setText(p.getDescripcion());
                    txtNuevNit.setText(txtNit.getText());    
                    txtNuevNombre.setText(txtNombre.getText());    
                    jButton12.setEnabled(false);
                    jButton13.setEnabled(true);
                    txtNuevPrecioCompra.setEnabled(true);
                    NuevoProducto.setLocationRelativeTo(this);          
                    NuevoProducto.setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
                }
                } else {          
                    mensaje.setText("Seleccione Primero el Proveedor");     
                    vistas.RetornaColor(txtNit);     
                }
       }
 }//GEN-LAST:event_jButton3ActionPerformed

    private void jXTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable1MouseClicked
       if(jXTable1.getRowCount()>0){
         jButton3.setEnabled(true);
         jButton2.setEnabled(true);
       }
    }//GEN-LAST:event_jXTable1MouseClicked

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
      
        if(vistas.CamposVacios(txtNuevCodigo,txtNuevTipo,txtNuevNombrepro,txtNuevprecio,txtNuevCantidad,txtNuevPrecioCompra,txtNuevStockMin,txtNuevNit,txtNuevNombre) && !txtNuevDescripcion.getText().equals("")){
            try {
                Producto pr;
                Proveedor prov;
                pr = ControlProducto.BuscarProducto(txtNuevCodigo.getText());
                prov = ControlProveedor.BuscarProveedor(txtNuevNit.getText());
                if(pr == null || pr.getCodigo().equals(i)){
                    pr = new Producto();
                    pr.setCodigo(txtNuevCodigo.getText());
                    pr.setTipo(txtNuevTipo.getText());
                    pr.setNombre(txtNuevNombrepro.getText());
                    pr.setPrecio(Double.parseDouble(txtNuevprecio.getText()));
                    pr.setCantidad(Double.parseDouble(txtNuevCantidad.getText()));
                    pr.setPreciocompra(Double.parseDouble(txtNuevPrecioCompra.getText()));
                    pr.setStockMin(Double.parseDouble(txtNuevStockMin.getText()));
                    pr.setDescripcion(txtNuevDescripcion.getText());
                    pr.setProveedor(prov);
                    ControlProducto.ModificarProducto(pr, i);
                    vistas.VaciarCampos(txtNuevCodigo,txtNuevTipo,txtNuevNombrepro,txtNuevprecio,txtNuevPrecioCompra,txtNuevStockMin,txtNuevNit,txtNuevNombre);
                    txtNuevCantidad.setText("0");
                    txtNuevDescripcion.setText("");
                    listaProductos();
                    NuevoProducto.setVisible(false);
                }else
                    mensaje.setText("Codigo Ya Existe..");
            } catch (SQLException ex) {
                Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }else{
          mensaje2.setText("No Pueden quedar Campos Vacios");
      }
        
        
    }//GEN-LAST:event_jButton13ActionPerformed

    private void txtNuevCodigoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNuevCodigoFocusGained
      
        mensaje2.setText("");
        
    }//GEN-LAST:event_txtNuevCodigoFocusGained

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       int x = jXTable1.getSelectedRow();
       txtCant.setText("");
       txtPrecioV.setText((int)Double.parseDouble(dtm2.getValueAt(x, 4).toString())+"");
       txtPrecioC.setText("");
       Cantidad.setLocationRelativeTo(this);
       Cantidad.setVisible(true);
        
    }//GEN-LAST:event_jButton2ActionPerformed

    private void txtCantActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCantActionPerformed
        
                        
    }//GEN-LAST:event_txtCantActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        int x = jXTable3.getSelectedRow();
        if(x<0){
          mensaje.setText("Selecione primero el producto ");
        }else{
            dtm3.removeRow(x);
            operaciones();
        }
        
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    Limpiar();
        
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
     Compra();
      
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jXTable3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable3MouseClicked
        if(jXTable3.getRowCount()>0)
            jButton5.setEnabled(true);
        
    }//GEN-LAST:event_jXTable3MouseClicked

    private void txtCantKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantKeyReleased
      vistas.validarnumero(txtCant, mensaje);
    }//GEN-LAST:event_txtCantKeyReleased

    private void txtPrecioCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPrecioCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPrecioCActionPerformed

    private void txtPrecioCKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPrecioCKeyReleased
        vistas.validarnumero(txtPrecioC, mensaje);
        
    }//GEN-LAST:event_txtPrecioCKeyReleased

    private void txtPrecioVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPrecioVActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPrecioVActionPerformed

    private void txtPrecioVKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPrecioVKeyReleased
       vistas.validarnumero(txtPrecioV, mensaje);
       
    }//GEN-LAST:event_txtPrecioVKeyReleased

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed

        mensaje.setText("");
        
        Cantidad.setVisible(false);     }//GEN-LAST:event_jButton15ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        if(txtCant.getText().equals("") || txtCant.getText().equals("0") || txtPrecioV.getText().equals("")|| txtPrecioV.getText().equals("0") || txtPrecioC.getText().equals("") || txtPrecioC.getText().equals("0")){
        mensaje.setText("No puede quedar campos Vacios ");
        } else{ 
           agregarproducto();     
           Cantidad.setVisible(false);   
        }
  }//GEN-LAST:event_jButton14ActionPerformed

    private void jXTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jXTable1KeyPressed
     if(evt.getKeyCode() == KeyEvent.VK_ENTER){
           int x = jXTable1.getSelectedRow();
           if(x>=0){
               txtCant.setText("");
               txtPrecioV.setText((int)Double.parseDouble(dtm2.getValueAt(x, 4).toString())+"");
               txtPrecioC.setText("");
               Cantidad.setLocationRelativeTo(this);
               Cantidad.setVisible(true);
           }
     }
        
    }//GEN-LAST:event_jXTable1KeyPressed

    private void CantidadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CantidadKeyPressed
        
        
    }//GEN-LAST:event_CantidadKeyPressed

    private void jXTable3KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jXTable3KeyPressed
     if(evt.getKeyCode() == KeyEvent.VK_DELETE){
            int x = jXTable3.getSelectedRow();
            if(x<0){
              mensaje.setText("Selecione primero el producto ");
            }else{
                dtm3.removeRow(x);
                operaciones();
            }
     }
        
    }//GEN-LAST:event_jXTable3KeyPressed

    private void jXTable4KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jXTable4KeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){ 
            int x = jXTable4.getSelectedRow();
             if(x >=0){
                  try {
                    String id = dtm.getValueAt(x, 0).toString();
                    Proveedor p = ControlProveedor.BuscarProveedor(id);
                    txtNombre.setText(p.getNombre());
                    txtNit.setText(p.getNit());
                    txtDireccion.setText(p.getDireccion());
                    txtTelefono.setText(p.getTelefono());
                    buscarProveedor.setVisible(false);
                    listaProductos();
                    vistas.VaciarCampos(mensaje);
                    jButton3.setEnabled(false);
                    jButton2.setEnabled(false);
                    jButton4.setEnabled(true);
                    jButton5.setEnabled(false);
                } catch (SQLException ex) {
                    Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_jXTable4KeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
   

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                VistaCompra dialog = new VistaCompra(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField BuscarProve;
    private javax.swing.JDialog Cantidad;
    private javax.swing.JComboBox ComboProveedor;
    public static javax.swing.JDialog NuevoProducto;
    private javax.swing.JDialog buscarProveedor;
    private javax.swing.JComboBox comboProducto;
    private com.toedter.calendar.JDateChooser fechaCompra;
    private javax.swing.JTextField iva;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private org.jdesktop.swingx.JXTable jXTable1;
    private org.jdesktop.swingx.JXTable jXTable3;
    private org.jdesktop.swingx.JXTable jXTable4;
    private javax.swing.JLabel mensaje;
    private javax.swing.JLabel mensaje2;
    private static javax.swing.JLabel numeroCompra;
    private javax.swing.JTextArea observacion;
    private static javax.swing.JTextField responsable;
    private static javax.swing.JTextField responsablenom;
    private javax.swing.JTextField subtotal;
    private javax.swing.JTextField total;
    private javax.swing.JTextField txtBuscarProducto;
    private javax.swing.JTextField txtCant;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtNit;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNuevCantidad;
    private javax.swing.JTextField txtNuevCodigo;
    private javax.swing.JTextArea txtNuevDescripcion;
    private javax.swing.JTextField txtNuevNit;
    private javax.swing.JTextField txtNuevNombre;
    private javax.swing.JTextField txtNuevNombrepro;
    private javax.swing.JTextField txtNuevPrecioCompra;
    private javax.swing.JTextField txtNuevStockMin;
    private javax.swing.JTextField txtNuevTipo;
    private javax.swing.JTextField txtNuevprecio;
    private javax.swing.JTextField txtPrecioC;
    private javax.swing.JTextField txtPrecioV;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration//GEN-END:variables

    public void ListarProveedor(){
        try {
            dtm.setNumRows(0);
            ControlProveedor.listarProveedor();
             Iterator it =  ControlProveedor.getProveedor().iterator();
                   while (it.hasNext()) {
                               Proveedor p = (Proveedor) it.next();
                               String[] fila = {p.getNit(), p.getNombre(), p.getDireccion(),p.getTelefono()};
                                 dtm.addRow(fila);
              
                    }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
       
}

    private void listaProveedornombre(String text) {
        try {
            dtm.setNumRows(0);
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlProveedor.con=mbd.getConexion();
             ControlProveedor.listarProveedor1("SELECT *FROM proveedores WHERE nombre LIKE '%"+text+"%'");
             Iterator iter1= ControlProveedor.getProveedor().iterator();
             while(iter1.hasNext()){
                 Proveedor pr =(Proveedor)iter1.next();
                String[] fila = {pr.getNit(), pr.getNombre(), pr.getDireccion(),pr.getTelefono()};
                dtm.addRow(fila);
        
             }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void listaProveedorNit(String text) {
        try {
            dtm.setNumRows(0);
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlProveedor.con=mbd.getConexion();
             ControlProveedor.listarProveedor1("SELECT *FROM proveedores WHERE nit LIKE '%"+text+"%'");
             Iterator iter1= ControlProveedor.getProveedor().iterator();
             while(iter1.hasNext()){
                 Proveedor pr =(Proveedor)iter1.next();
                String[] fila = {pr.getNit(), pr.getNombre(), pr.getDireccion(),pr.getTelefono()};
                dtm.addRow(fila);
        
             }
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
}
     private void listaProductos() {
        try {
            dtm2.setNumRows(0);
            Proveedor p = ControlProveedor.BuscarProveedor(txtNit.getText());
            ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
            mbd.conectar();      
            ControlProducto.con = mbd.getConexion();
            ControlProducto.listarProducto1("SELECT *FROM productos WHERE codproveedor='"+p.getNit()+"'");
            Iterator it =  ControlProducto.getProducto().iterator();
                   while (it.hasNext()) {
                               Producto pro = (Producto) it.next();
                               int stm = (int) pro.getStockMin();
                               int can = (int) pro.getCantidad();
                               String[] fila = {pro.getCodigo(), pro.getTipo(), pro.getNombre(),pro.getDescripcion(), pro.getPrecio()+"",pro.getPreciocompra()+"", can+"", stm+""};
                                 dtm2.addRow(fila);
              
                    }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
 }
      private void listaBuscarProducto() {
        try {
            dtm2.setNumRows(0);
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlProducto.con=mbd.getConexion();
             String text = txtBuscarProducto.getText();
             String cod = txtNit.getText();
               if(comboProducto.getSelectedItem().toString().equals("Nombre"))
                  ControlProducto.listarProducto1("SELECT *FROM productos WHERE nombre LIKE '%"+text+"%' AND codproveedor='"+cod+"'");
                else
                   ControlProducto.listarProducto1("SELECT *FROM productos WHERE codigo LIKE '%"+text+"%' AND codproveedor='"+cod+"'");
             
             Iterator iter1= ControlProducto.getProducto().iterator();
             while(iter1.hasNext()){
                 Producto pro =(Producto)iter1.next();
                 String[] fila = {pro.getCodigo(), pro.getTipo(), pro.getNombre(),pro.getDescripcion(), pro.getPrecio()+"",pro.getCantidad()+"",pro.getPreciocompra()+"", pro.getStockMin()+""};
                 dtm2.addRow(fila);
        
             }
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
}
public void agregarproducto(){
       
        int x = jXTable1.getSelectedRow();
           if(x < 0){
             mensaje.setText("Selecione primero el producto ");
        }else{
                try {
                    String e= dtm2.getValueAt(x, 0).toString();
                    Producto p=ControlProducto.BuscarProducto(e);
                    if(dtm2.getValueAt(x, 0).toString().equals(e)){
                        double pre= Double.parseDouble(txtPrecioC.getText());
                        double can=Double.parseDouble(txtCant.getText());
                        double valor =pre*can;
                        int can1 = (int) can;
                        String[] fila={p.getCodigo(),p.getNombre(),p.getDescripcion(),"$"+txtPrecioV.getText(),"$"+txtPrecioC.getText(),can1+"","$"+valor};
                        dtm3.addRow(fila);
                        operaciones();
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
                }
           }
    
}
    
public void operaciones(){
         double subto=0;
         double tot=0;
         double iv=0;
         if(jXTable3.getRowCount()==0){
             subtotal.setText("");
             iva.setText("");
             total.setText("");
         }else{
         for(int i=0;i<dtm3.getRowCount();i++){
            try {
                StringTokenizer sub = new StringTokenizer(dtm3.getValueAt(i,6).toString(),"$");
                double subt=Double.parseDouble(sub.nextToken());
                subto = subto+subt;
                String valor="";
                valor = String.valueOf(subto);
                subtotal.setText("$"+valor);
                Variable va = ControlVariable.buscarVariables("01");
                iv = subto*va.getValor();
                iva.setText("$"+iv);
                tot = subto+iv;
                total.setText("$"+tot);
            } catch (Exception ex) {
                Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
         }
    
}
    public static void Iniciar() {
        try {             
            Usuario usu=ControlUsuario.BuscarUsuario(Principal.codigo.getText()); 
            responsable.setText(usu.getId());
            responsablenom.setText(usu.getNombre());
            numeroCompra.setText( ControlCompra.ultimaCompra());
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void Limpiar() {
       dtm3.setNumRows(0);
       subtotal.setText("");
       iva.setText("");
       total.setText("");
       observacion.setText("");
       jButton5.setEnabled(false);
       mensaje.setText("");
    }

    private void LimpiarNuevoProducto() {
       txtNuevCodigo.setText("");
       txtNuevTipo.setText("");
       txtNuevNombrepro.setText("");
       txtNuevprecio.setText("");
       txtNuevCantidad.setText("0");
       txtNuevPrecioCompra.setText("0");
       txtNuevStockMin.setText("");
       txtNuevDescripcion.setText("");
       mensaje2.setText("");
    }

    private void Compra() {
        if(jXTable3.getRowCount()==0){
          mensaje.setText("Agregue un Producto a la Compra");
      }else{
        try {
            Compra c = new Compra();
            Producto pr;
            DetalleCompra dc = new DetalleCompra();
            c.setNumero(numeroCompra.getText());
            c.setFecha(cfecha.format(fechaCompra.getDate()));
            StringTokenizer st= new StringTokenizer(total.getText(),"$");
            c.setTotal(Double.parseDouble(st.nextToken()));
            StringTokenizer st2= new StringTokenizer(iva.getText(),"$");
            c.setIva(Double.parseDouble(st2.nextToken()));
            c.setUsuario(ControlUsuario.BuscarUsuario(responsable.getText()));
            ControlCompra.RegistrarCompra(c);
            for(int i=0; i<dtm3.getRowCount();i++){
                pr = ControlProducto.BuscarProducto(dtm3.getValueAt(i, 0).toString());
                dc.setProducto(pr);
                dc.setCompra(c);
                dc.setCantidad(Double.parseDouble(dtm3.getValueAt(i, 5).toString()));
                StringTokenizer st3= new StringTokenizer(dtm3.getValueAt(i, 6).toString(),"$");
                dc.setSubtotal(Double.parseDouble(st3.nextToken()));
                dc.setCantidadActual(pr.getCantidad());
                Double cant = pr.getCantidad();
                cant = cant + dc.getCantidad();
                pr.setCantidad(cant);
                StringTokenizer st4= new StringTokenizer(dtm3.getValueAt(i, 3).toString(),"$");
                pr.setPrecio(Double.parseDouble(st4.nextToken()));
                StringTokenizer st5= new StringTokenizer(dtm3.getValueAt(i, 4).toString(),"$");
                pr.setPreciocompra(Double.parseDouble(st5.nextToken()));
                ControlProducto.ModificarProducto(pr, pr.getCodigo());
                dc.setCantidadFinal(cant);
                ControlDetalleCompra.RegistrarDetalleCompra(dc);
                
            }
            listaProductos();
            Limpiar();
            Iniciar();
            JOptionPane.showMessageDialog(this, "Compra Realizada");
            
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    }

}